{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:From /root/anaconda3/envs/mytf/lib/python3.8/site-packages/tensorflow/python/compat/v2_compat.py:96: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "non-resource variables are not supported in the long term\n"
     ]
    }
   ],
   "source": [
    "import tensorflow.compat.v1 as tf\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "tf.disable_v2_behavior()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD4CAYAAAD8Zh1EAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/d3fzzAAAACXBIWXMAAAsTAAALEwEAmpwYAAAP5UlEQVR4nO3df6zdd13H8edrt13s+GGJu5KtnXYmozj5NTxuMUQcIrYbaJH4x4ZiWEyWJduCMakME0VDDJpFw5INm2ZMICKNwpiVTKqJIBqC7nYdjDJKmvKjt0V7Jw4dNNnavf3jni23t6f3nHv6vT23nz0fSdPz/Xw/5/N9f05yX/32cz7nnlQVkqTz3wWTLkCS1A0DXZIaYaBLUiMMdElqhIEuSY1YM6kLX3zxxbVp06ZJXV6Szkt79+59vKqmB52bWKBv2rSJmZmZSV1eks5LSb51pnMuuUhSIwx0SWqEgS5JjTDQJakRBrokNWLoLpck9wFvAY5V1SsGnA9wF3A98APgnVX1cNeFAjyw7wh37jnA0SeOc+n6dWzfspm3XrVhouM9sO8If7h7P08cfxqAl1y0lvf+8k8BLHvsrufXtS7rG2es1fj6rMaa9PyVYb9tMcnrgSeBj54h0K8Hbmc+0K8B7qqqa4ZduNfr1XK2LT6w7wjvuf9Rjj998rm2d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q+ez/peDP9k/XNv/09S77Uk2Am8G7p10LRpPkhcDrwc+BFBVT7UU5uAa+jmVZBNwFfDvEy6lc/3liEeAY8A/VVVrc/wA8LvAMxOuY6UV8I9J9ia5edLFdOwngDngL/tLZ/cmecGki+qSgX6OJHkh8Engt6vqfyddT9eq6mRVvYb575O9OkkzS2hJ3gIcq6q9k67lHHhdVb0WuA64tb8s2oo1wGuBv6iqq4DvA3dMtqRuGejnQH9d+ZPAx6rq/knXs5L6/4X9HPNfR9iK1wG/0l9f3gX8QpK/mmxJK6Oqjvb/PgZ8Crh6shV1ahaYXfC/x08wH/DNMNBXWP8Nww8Bj1XVn0+6npWQZDrJ+v7jdcAvAl+baFEdqqr3VNXGqtrE/Jek/3NV/caEy+pckhf037invxTxS0AzO9Cq6j+Bw0k295veCDSzOQFG/E7RlZLk48C1wMVJZoH3VtWHJlnTCngd8A7g0f4aM8Dv9b+ntRWXAB9JMsX8TcLfVFWzW/sa9lLgU/P3IKwB/rqqPjPZkjp3O/Cx/g6XQ8BNE66nU370X5Ia4ZKLJDXCQJekRhjoktQIA12SGmGgS1IjDHRJaoSBLkmN+H8CsGTQHnVr6AAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "x_label0=np.random.normal(5,1,10)\n",
    "x_label1=np.random.normal(2,1,10)\n",
    "xs=np.append(x_label0,x_label1)\n",
    "labels=[0.]* len(x_label0)+[1.]*len(x_label1)\n",
    "plt.scatter(xs,labels)\n",
    "learning_rate=0.01\n",
    "training_epochs=1000\n",
    "\n",
    "X=tf.placeholder('float')\n",
    "Y=tf.placeholder('float')\n",
    "def model(X,w):\n",
    "    return tf.add(tf.multiply(w[1],tf.pow(X,1)),\n",
    "                 tf.multiply(w[0],tf.pow(X,0)))\n",
    "w=tf.Variable([0.,0.],name='parameters')\n",
    "y_model=model(X,w)\n",
    "cost=tf.reduce_sum(tf.square(Y-y_model))\n",
    "\n",
    "train_op=tf.train.GradientDescentOptimizer(learning_rate).minimize(cost)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "sess=tf.Session()\n",
    "init=tf.global_variables_initializer()\n",
    "sess.run(init)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 82.17229\n",
      "100 nan\n",
      "200 nan\n",
      "300 nan\n",
      "400 nan\n",
      "500 nan\n",
      "600 nan\n",
      "700 nan\n",
      "800 nan\n",
      "900 nan\n"
     ]
    }
   ],
   "source": [
    "for epoch in range(training_epochs):\n",
    "    sess.run(train_op,feed_dict={X:xs,Y:labels})\n",
    "    current_cost=sess.run(cost,feed_dict={X:xs,Y:labels})\n",
    "    if epoch %100==0:\n",
    "        print(epoch,current_cost)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
